﻿// ---------------------------------------------------------------------
// Partial của lớp SSupervisor
//
// Nội dung:
//    + Các hàm xử lý lúc nhận được message từ client trong lượt Main phase 1 ( Đổi Trạng Thái )
//
// Copyright (c) 2009 YugiOH
//
// Nguyễn Hữu Lê Trọng Tín      YM: ilu2009             ĐT: 0906520611 
// Võ Phước Hậu                 YM: phuochauspkt        ĐT: 0979202707
// ---------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using Yugi.Client.Card;
using System.Threading;
using ManagementEffect;


namespace ServerYuGi
{
    public partial class SSupervisor
    {
        void Process_CARD_DOITRANGTHAI(params object[] param)
        {         
            int IDCard = (int)param[0];
            SPlayer player = LayPlayer(TurnManager.IDPlayerTrongLuot);
            SPlayer playerother = LayPlayerKhacVoiPlayerDangTrongLuot();
            SCard tmp = player.LayCardTrenBan(IDCard);
            YBaseCard card = tmp.MyYBaseCard;  
            YMSG TrangThai = (YMSG)param[1];

           

            switch (TrangThai)
            {
                case YMSG.CARD_TRANGTHAI_DUNG_MO:
                    if (card.CardType == YType.Monster)                   
                        tmp.TrangThai = YMSG.CARD_TRANGTHAI_NAM_MO;                     
                    break;
                case YMSG.CARD_TRANGTHAI_DUNG_UP:
                    if (card.CardType == YType.Spell || card.CardType == YType.Trap)                  
                        tmp.TrangThai = YMSG.CARD_TRANGTHAI_DUNG_MO;                  
                    break;
                case YMSG.CARD_TRANGTHAI_NAM_MO:
                    if (card.CardType == YType.Monster)                   
                        tmp.TrangThai = YMSG.CARD_TRANGTHAI_DUNG_MO;                
                    break;
                case YMSG.CARD_TRANGTHAI_NAM_UP:
                    if (card.CardType == YType.Monster)                   
                        tmp.TrangThai = YMSG.CARD_TRANGTHAI_DUNG_MO;                
                    break;
                
            }          
             SendMessage_CARD_DOITRANGTHAI_XONG_ToID(playerother.ID, IDCard, tmp.TrangThai);
             //Update Block
             player.Block.DuocPhep_DoiTrangThai.Remove(IDCard);
             if(TurnManager.GetStateNow() == EnumState.MainPhase1)
                player.Block.DuocPhep_TanCong.Add(IDCard);


            List<YCheckPoint> checkpoint=null;
            bool check;

            if((TrangThai == YMSG.CARD_TRANGTHAI_NAM_UP) && 
                (tmp.TrangThai == YMSG.CARD_TRANGTHAI_NAM_MO || tmp.TrangThai == YMSG.CARD_TRANGTHAI_DUNG_MO))
            {
                /*------------------Check CheckPoint Change Position------------------------*/
                ExEffectManager.IDPlayerCheck = TurnManager.IDPlayerTrongLuot;
                ExEffectManager.CheckPointNow = YCheckPoint.MONSTER_FLIP;
                ExEffectManager.Init();
                RevMSGmanager.isPlayerKoTrongLuot = true;
                checkpoint = new List<YCheckPoint> { YCheckPoint.MONSTER_FLIP };
                check = Check_EffectExcute(checkpoint, ExEffectManager.IDPlayerCheck, "api_manager,flip_id", api_manager,tmp.MyYBaseCard.ID);
                RevMSGmanager.Init();
                //----------------------------------------------------------//
            }


            /*------------------Check CheckPoint Change Position------------------------*/
            ExEffectManager.IDPlayerCheck = TurnManager.IDPlayerTrongLuot;
            ExEffectManager.CheckPointNow = YCheckPoint.MONSTER_CHANGEPOSTITION;
            ExEffectManager.Init();
            RevMSGmanager.isPlayerKoTrongLuot = true;
            checkpoint = new List<YCheckPoint> { YCheckPoint.MONSTER_CHANGEPOSTITION };
            check = Check_EffectExcute(checkpoint, ExEffectManager.IDPlayerCheck, "api_manager,change_id,trangthai_cu,trangthai_moi", api_manager,tmp.MyYBaseCard.ID ,TrangThai, tmp.TrangThai);
            RevMSGmanager.Init();
            //----------------------------------------------------------//
        }
    }
}
